﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Service;
using Model;


namespace ItaServicos.Controllers
{
    public class ServicoController : Controller
    {
        
        
        private GerenciadorServico gServico;
     
        public ServicoController()
        {
            gServico = new GerenciadorServico();
        }
        //
        // GET: /Servico/

        public ActionResult Index()
        {
            
            return View(gServico.ObterTodos());
        }

        //
        // GET: /Servico/List/5
        [HttpGet]
        public ActionResult List()
        {
            
            return View();
        }

        //
        // GET: /Servico/Details/5
        [HttpGet]
        public ActionResult Details(int id)
        {
            ServicoModel servico = gServico.Obter(id);
            return View(servico);
            
        }

        //
        // GET: /Servico/Create

        [HttpGet]
        public ActionResult Create()
        {
           // GerenciadorEspecialidade gesp =new GerenciadorEspecialidade();
            // ViewData["page"] = new SelectList(gesp.ObterTodos());
            //ViewData["UserID"] = new SelectList(tb_especialidade.usuarioSet, "UserID", "Login", key); Se
            return View();
        }

       
       

        //
        // POST: /Servico/Create

        [HttpPost]
        public ActionResult Create(ServicoModel servico)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    gServico.Inserir(servico);
                    return RedirectToAction("Index");
                }

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
        
        //
        // GET: /Servico/Edit/5
        [HttpGet]
        public ActionResult Edit(int id)
        {
            ServicoModel servico = gServico.Obter(id);
            return View(servico);
            
        }

        //
        // POST: /Servico/Edit/5

        [HttpPost]
        public ActionResult Edit( ServicoModel servico)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    gServico.Editar(servico);
                    return RedirectToAction("Index");
                }
 
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /Servico/Delete/5
        [HttpGet]
        public ActionResult Delete(int id)
        {
            ServicoModel servico = gServico.Obter(id);
            return View(servico);
            
        }

        //
        // POST: /Servico/Delete/5

        [HttpPost]
        public ActionResult DeleteComfirmar(int id)
        {
            try
            {
                gServico.Remover(id);
                return RedirectToAction("Index");
 
             }
            catch
            {
                return View();
            }
        }

        protected override void Dispose(bool disposing)
        {
            base.Dispose(disposing);
        }
    }
}
